import string
import random
from PIL import Image, ImageDraw, ImageFont, ImageFilter

def Random_char(char_long):
    """生成char_long长度的字符串"""
    chars = ''
    for i in range(char_long):
        chars +=random.choice(string.ascii_letters)
    return chars

def Random_color1():    #随机颜色1
    return (random.randint(64,255),random.randint(64,255),random.randint(64,255))

def Random_color2():    #随机颜色2
    return (random.randint(32,127),random.randint(32,127),random.randint(64,127))


def test():
    print(Random_char(10))


if __name__=='__main__':
    width = 100*4
    height = 100
    image = Image.new('RGB',(width, height), (255,255,255))

    #创建Font对象
    font = ImageFont.truetype('arial.ttf',50)

    #创建Draw对象
    draw = ImageDraw.Draw(image)

    #填充每一个像素
    for x in range(width):
        for y in range(height):
            draw.point((x,y),fill = Random_color1())

    #输出文字
    for i,t in enumerate(Random_char(4)):
        draw.text((100*i+35,20), t,font = font,fill = Random_color2())

    #模糊
    image = image.filter(ImageFilter.BLUR)
    image.save('test.jpg','jpeg')

